package 
{	
	import collada.DAE;
	import flash.display.Sprite;
	import racingGame.ui.Help;
	import racingGame.ui.InGame;
	import racingGame.ui.ScreenManager;
	
	import racingGame.core.Stats;
	import racingGame.ui.*;
	import racingGame.assets.Textures;
	import racingGame.events.ScreenEvent;
	
	[SWF(backgroundColor = "#0099FF", frameRate = "100", width = "600", height = "400")]
	
	public class RacingGameMain extends Sprite 
	{	
		public static const CAR_TEST :uint = 0;
		public static const TRACK_TEST :uint = 1;
		public static var testMode :uint;
		
		
		/**** Private Variables ****/
		
		private var _gameContainer 	:Sprite;
		private var _debugContainer	:Sprite;
		private var _screenManager	:ScreenManager;
		
		
		/**** Public Methods ****/
		
		public function RacingGameMain() 
		{
			_gameContainer = new Sprite();
			_debugContainer = new Sprite();
			addChild(_gameContainer);
			addChild(_debugContainer);
			
			_screenManager = new ScreenManager();
			_gameContainer.addChild(_screenManager);
			_debugContainer.addChild(new Stats());
			
			addEventListener(ScreenEvent.SCREEN_EXIT, onScreenExit);
			_screenManager.push(new MainMenu());
			
			testMode = TRACK_TEST; _screenManager.push(new InGame());
        }
		
		
		/**** Callback Methods ****/
		
		private function onScreenExit(e :ScreenEvent) :void 
		{	
			// If there ain't any screen next, just pop the last pushed:
			if (!e.nextScreenType) {
				
				_screenManager.pop();
			}
			// There is a screen next, but is not inside the stack yet:
			else if(!_screenManager.isPushed(e.nextScreenType)) {
				
				_screenManager.push(new e.nextScreenType());
			}
			// The next screen is inside the stack; Pop until we reach that screen:
			else {
				
				while (!(_screenManager.peek() is e.nextScreenType)) {
					
					_screenManager.pop();
				}
			}
		}
		
		
	}
	
	
}